package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppHelp;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppHelpServiceDao.java
 * @Description TODO
 * @createTime 2021年07月23日 14:49:00
 */
@Repository
public class AppHelpServiceDao extends BaseDao<AppHelp> {

    public void saveOrUpdate(AppHelp appHelp) {
        if (appHelp.getId() == null || appHelp.getId() == 0) {
            appHelp.setId(this.add(appHelp));
        } else {
            this.update(appHelp);
        }
    }

    public List<AppHelp> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_help where 1=1 ");
        if (StringEx.isNotNull(paramap.get("biaoti"))) {
            str.append(" and biaoti = ? ");
            list.add(paramap.get("biaoti"));
        }

        if (StringEx.isNotNull(paramap.get("status"))) {
            str.append(" and status = ? ");
            list.add(paramap.get("status"));
        }

        String sql = str.toString();
        return this.queryList(sql, list, AppHelp.class, splitPageBean);
    }

    public List<AppHelp> findList(Integer type, String title) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_help where 1=1");
        if (StringEx.isNotNull(type)) {
            str.append(" and type = ?");
            list.add(type);
        }
        if (StringEx.isNotNull(title)) {
            str.append(" and title like '%"+title+"%' or content like '%"+title+"%'");
        }
        str.append(" order by sort asc");
        String sql = str.toString();
        return this.queryList(sql, list, AppHelp.class);
    }

    public void delete(Integer id) {
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_help where id = ? ");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }

}